using System;
using System.Collections.Generic;
using UnityEngine;

namespace NodeCanvas.Variables
{
	[AddComponentMenu("")]
	public class CurveData : VariableData
	{
		[Serializable]
		private class SerializedKey
		{
			public float time;

			public float value;

			public float inTangent;

			public float outTangent;
		}

		public AnimationCurve value = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);

		public override object objectValue
		{
			get
			{
				return value;
			}
			set
			{
				this.value = (AnimationCurve)value;
			}
		}

		public override object GetSerialized()
		{
			List<SerializedKey> list = new List<SerializedKey>();
			Keyframe[] keys = value.keys;
			for (int i = 0; i < keys.Length; i++)
			{
				Keyframe keyframe = keys[i];
				SerializedKey serializedKey = new SerializedKey();
				serializedKey.time = keyframe.time;
				serializedKey.value = keyframe.value;
				serializedKey.inTangent = keyframe.inTangent;
				serializedKey.outTangent = keyframe.outTangent;
				list.Add(serializedKey);
			}
			return list;
		}

		public override void SetSerialized(object obj)
		{
			List<Keyframe> list = new List<Keyframe>();
			foreach (SerializedKey item in (List<SerializedKey>)obj)
			{
				list.Add(new Keyframe(item.time, item.value, item.inTangent, item.outTangent));
			}
			value.keys = list.ToArray();
		}
	}
}
